package com.itheima.mapper;

import com.itheima.pojo.Dept;
import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * @author :速趴赛亚锦
 * @date :2024/3/16 18:01
 */
@Mapper
public interface EmpMapper {
    /**
     *
     * @author :速趴赛亚锦            -----【分页查询】
     * @create :2024/03/17 11:26
     */
    //从数据库获取总记录数据
//    @Select("select count(*) from mybatis_tlias.emp")
//    Long count();

    //获取当前页数并且展示结果
//    @Select("select * from mybatis_tlias.emp limit #{beginIndex},#{pageSize}")
//    List<Emp> selectPage(Integer beginIndex,Integer pageSize);

    /**
     *
     * @author :速趴赛亚锦  ------------------------【使用插件后的分页查询 = 需要导入依赖】
     * @create :2024/03/17 11:26
     * ============================================== 接收六个参数的完整分页查询
     */
//     @Select("select * from mybatis_tlias.emp")
//     List<Emp> page();
      List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);


    /**
     *
     * @author :速趴赛亚锦 -----------------【批量删除操作使用xml完成批量删除】
     * @create :2024/03/17 13:50
     */
    void delete(ArrayList<Integer> ids);

    /**
     *------------------------------【新增员工】
     * @author :速趴赛亚锦
     * @create :2024/03/17 14:57
     */
    @Insert("insert into mybatis_tlias.emp (username, name, gender, image, job, entrydate, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);


    /**
     * @author :速趴赛亚锦
     * @create :2024/03/17 15:12
     *
     * =============================【根据id回显数据和更新】
     */
    @Select("select *from mybatis_tlias.emp where id=#{id}")
    Emp findById(Integer id);
//    @Update("update mybatis_tlias.emp set username=#{username},name=#{name},gender=#{gender},image=#{image},job=#{job},entrydate=#{entrydate},update_time=#{updateTime}" +
//            "where id=#{id}")
    //移步去XMl里面写
    void update(Emp emp);


    /**
     *
     * @author :速趴赛亚锦===============【登录操作】
     * @create :2024/03/18 13:03
     */
    @Select("select * from mybatis_tlias.emp where username=#{username} and password=#{password}")
    Emp getUserByUsernameAndPassword(Emp emp);
}
